fix: local gateway connections recover after listener or token drift - #1053
fix: local gateway connections recover after listener or token drift#1053bkudiess wants to merge 2 commits into
Conversation
|
Codex review: found issues before merge. Reviewed July 27, 2026, 3:08 AM ET / 07:08 UTC. ClawSweeper reviewWhat this changesThis PR adds managed-local gateway listener provenance checks, role-specific token recovery, explicit disconnect intent, and bounded WSL gateway self-repair for setup-managed local connections. Merge readiness⛔ Blocked until stronger real behavior proof is added - 7 items remain Keep this draft PR open for human review. The legacy migration currently classifies any migrated loopback gateway as setup-managed when a local setup-state file exists, which can apply automatic WSL repair and credential-gating behavior to a manually configured localhost gateway. Priority: P1 Review scores
Verification
How this fits togetherGateway records feed the connection manager, which resolves credentials and connects the operator and Windows node to a gateway. For setup-managed local WSL gateways, the new path also verifies the listener owner and may perform bounded recovery before reconnecting. flowchart LR
A[Stored gateway records] --> B[Gateway migration and selection]
C[Setup state] --> B
B --> D[Connection lifecycle]
D --> E[Listener ownership check]
E --> F[Credential authorization]
E --> G[Bounded WSL repair]
F --> H[Operator and node connection]
G --> H
Decision needed
Why: The patch introduces a new default recovery and credential-gating policy for persisted gateway records. Source inspection shows the migration boundary is broader than the stated app-owned WSL scope, so maintainers must confirm the intended upgrade contract before a mechanical fix can be accepted. Before merge
Findings
Agent review detailsSecurityNeeds attention: The listener and token protections are security-sensitive, but broad legacy localhost adoption can apply those controls and destructive remediation to endpoints not proven to be app-owned. Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Restrict setup-managed migration to records that can be positively linked to the setup-owned endpoint, preserve manual localhost records as manual, document the resulting ownership boundary, and attach redacted current-head upgrade and fault-recovery proof before merge. Do we have a high-confidence way to reproduce the issue? No, not as an executed current-head runtime reproduction. The source provides a high-confidence path: migrate a legacy manual localhost record while a setup-state file exists, then observe that it receives setup-managed metadata and becomes eligible for managed-local policy. Is this the best way to solve the issue? No. Listener ownership checks are a reasonable safety direction, but using ambient setup state to adopt every migrated localhost record is not the narrowest maintainable upgrade path; ownership must be positively linked to the persisted endpoint. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against acf4ab1d2b02. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Add trusted endpoint provenance, role-aware credential recovery, explicit operator intent, and bounded managed-WSL repair so local gateway failures recover safely without leaking stronger credentials or overriding disconnects. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve WSL shell variables through stdin, isolate the Windows PowerShell module path for Authenticode verification, and account for relay family translation. Update the keepalive E2E contract to recognize an already-proven setup keepalive without spawning a duplicate. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
c2e1372 to
ff2ad8b
Compare
What Problem This Solves
Fixes an issue where users connected to a setup-managed local WSL gateway could
be left in misleading re-pair/token states or unstable reconnect loops when a
stale native gateway owned the local port, the WSL gateway was wedged, or a
role-specific device token drifted.
Why This Change Was Made
This makes
GatewayConnectionManagerthe canonical operator/node lifecycle anduser-intent owner, adds a shared local-listener provenance service, and adds a
bounded managed-WSL repair monitor/coordinator. Strong shared/bootstrap
credentials are sent only after the expected local gateway owner is proven;
unknown listeners are never killed, and explicit Disconnect/Stop intent is
never overridden by automatic repair.
The old owners were scattered UI/client reconnect paths and best-effort port
diagnostics. The new owners are the connection manager for lifecycle and
credential recovery,
ManagedLocalGatewayPortProvenanceServicefor endpointidentity/remediation, and the monitor/coordinator for bounded automatic repair.
User Impact
Setup-managed local gateways now recover automatically from stale listener
collisions, WSL service/VM failures, and role-specific device-token mismatch.
When ownership cannot be proven, the UI reports a local port conflict instead
of incorrectly asking the user to re-pair.
Evidence
OpenClaw native listener, left the task disabled, restored signed
wslrelay.exeownership in about 50 seconds, returned the WSL systemd gatewayto
active, and refreshedLastConnected.relay without terminating an unknown process.
127.0.0.1:18789is owned byC:\Program Files\WSL\wslrelay.exe(PID 38548);OpenClawGatewayisactive/running(MainPID 483).9d418433launched successfully in isolated mode and remainedresponsive as PID 41088.
c2e13727completed the real fresh-distro setup/connect,revocation-recovery, and network-recovery E2E shards. This also proved signed
wslrelayverification under a PowerShell 7 parent and dual-stack Windowsrelay projection onto the expected systemd-owned WSL socket.
Claude Opus 4.8 95/100, Gemini 3.1 Pro 100/100; no material findings.
material blockers and confirmed model-catalog, settings, exec-approval, and
connection-recovery behavior remain wired.
Change Type
Scope
winnodeValidation
.\build.ps1dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restoredotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-restoredotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restoredotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restoreKnown telemetry listener tests flaked transiently during exploratory runs.
Their isolated reruns passed, and the complete required closeout rerun passed.
Real Behavior Proof
OpenClawGateway, setup-managedloopback gateway on port 18789.
c2e13727..\run-app-local.ps1 -NoBuild -AllowNonMain -Isolated; inspected theaddress-specific Windows listener and WSL systemd service; repeated controlled
native-listener collision/recovery trials before the mechanical rebase; ran
all three CI setup E2E filters on the current head.
relay owns the loopback listener; WSL service is active/running; controlled
collisions self-repaired without sending strong credentials to or killing an
unproven owner; current-head fresh-distro setup, revocation, network recovery,
and keepalive idempotence all passed.
user intent and unknown-listener safety remain authoritative.
Yes/No/N/A): N/A; copiedterminal/runtime evidence is included above.
global singleton already owned by another worktree (PID 2496), which was not
terminated. Current-head runtime behavior was instead exercised through the
real fresh-distro E2E shards; non-isolated collision recovery was exercised
repeatedly on the identical feature snapshot before the conflict-free rebase.
Security Impact
Yes/No): No.Yes/No): Yes.Yes/No): Yes, local listener/provenance andreconnect probes only.
Yes/No): Yes, bounded repaircan restart the expected WSL service/VM and disable/stop only a fully proven
obsolete OpenClaw native task/process.
Yes/No): No.Yes, explain the risk and mitigation: shared/bootstrapcredentials are now gated by complete Windows IPv4/IPv6 listener capture,
signed relay, expected-distro systemd MainPID target-port ownership, and
listener recapture. Destructive remediation additionally proves native
task/profile/process lineage and PID start identity. Unknown owners fail closed.
Compatibility and Migration
Yes/No): Yes.Yes/No): No.Yes/No): Yes, automatic only.Dev, direct-override, and legacy
Local (<distro>)records are migrated orresolved in place.
Review Conversations